Conversation
| avgy += b.yc | ||
| bcount += 1 | ||
|
|
There was a problem hiding this comment.
Found the following improvement in Function Boid.getavgpos:
|
|
||
| avgd = avgd/bcount | ||
| return avgd | ||
|
|
||
| return avgd/bcount |
There was a problem hiding this comment.
Function Boid.getavgdir refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if self.alone: | ||
| pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) | ||
| else: | ||
| pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) # just draws a rectangle at where the average position is | ||
| pygame.draw.rect(screen, (0, 0, 255), (ax%width, ay%height, 5, 5)) | ||
| relx = ax - self.x | ||
| rely = ay - self.y | ||
|
|
There was a problem hiding this comment.
Function Boid.cohesion refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
This removes the following comments ( why? ):
# just draws a rectangle at where the average position is
| if rx > 0 and ry > 0: | ||
|
|
||
| if rx > 0 and ry > 0 or (rx <= 0 or ry >= 0) and (rx >= 0 or ry >= 0): | ||
| self.rot += tcs | ||
| elif rx > 0 and ry < 0: | ||
| self.rot -= tcs | ||
| elif rx < 0 and ry < 0: | ||
| self.rot -= tcs | ||
| else: | ||
| self.rot += tcs |
There was a problem hiding this comment.
Function Boid.separate refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if)
|
|
||
| boids = [] | ||
| boids = [ | ||
| Boid( | ||
| randint(0, width), | ||
| randint(0, height), | ||
| pygame.image.load("boid.png"), | ||
| 150, | ||
| ) | ||
| for _ in range(100) | ||
| ] | ||
|
|
||
|
|
There was a problem hiding this comment.
Lines 209-224 refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Replace unused for index with underscore (
for-index-underscore)
This removes the following comments ( why? ):
# add boids
| avgy += b.y | ||
| bcount += 1 | ||
|
|
There was a problem hiding this comment.
Found the following improvement in Function Boid.getavgpos:
| boids = [] | ||
| boid = Boid(100, 100, pygame.image.load("boid.png")) | ||
|
|
||
| boids.append(Boid(randint(500, 1000), randint(500, 1000), pygame.image.load("boid.png"))) | ||
| boids = [ | ||
| Boid(randint(500, 1000), randint(500, 1000), pygame.image.load("boid.png")) | ||
| ] | ||
|
|
There was a problem hiding this comment.
Lines 120-134 refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge append into list declaration (
merge-list-append)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.92%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!